package com.tcwlkj.uuService.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ZoomControls;

import com.baidu.location.LocationClient;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.RouteLine;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.route.BikingRoutePlanOption;
import com.baidu.mapapi.search.route.BikingRouteResult;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.IndoorRouteResult;
import com.baidu.mapapi.search.route.MassTransitRouteLine;
import com.baidu.mapapi.search.route.MassTransitRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRouteResult;
import com.tcwlkj.uuService.MyApp;
import com.tcwlkj.uuService.NetWork.HttpCallBack;
import com.tcwlkj.uuService.NetWork.RetrofitUtils;
import com.tcwlkj.uuService.R;
import com.tcwlkj.uuService.baidu.overlay.BikingRouteOverlay;
import com.tcwlkj.uuService.baidu.overlay.OverlayManager;
import com.tcwlkj.uuService.model.CommonResponse;
import com.tcwlkj.uuService.model.OrderModel;
import com.tcwlkj.uuService.utils.ChcheUtils;
import com.tcwlkj.uuService.utils.EventCenter;
import com.tcwlkj.uuService.utils.PreferencesUtils;
import com.tcwlkj.uuService.utils.ToastUtil;
import com.tcwlkj.uuService.utils.Tools;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * Created by Administrator on 2017/10/14 0014.
 */
public class PushOrderActivity extends Activity implements BaiduMap.OnMapClickListener,
        OnGetRoutePlanResultListener {
    @Bind(R.id.lay_detail_snatch)
    LinearLayout lay_detail_snatch;
    @Bind(R.id.lay_map_snatch)
    LinearLayout lay_map_snatch;
    @Bind(R.id.tv_detail_snatch)
    TextView tv_detail_snatch;
    @Bind(R.id.tv_map_snatch)
    TextView tv_map_snatch;
    @Bind(R.id.mapview_snatch)
    MapView mapviewSnatch;
    @Bind(R.id.tv_ordertype_snatch)
    TextView tv_ordertype_snatch;
    @Bind(R.id.tv_distancd)
    TextView tv_distancd;
    @Bind(R.id.tv_location_start_snatch)
    TextView tv_location_start_snatch;
    @Bind(R.id.tv_location_end_snatch)
    TextView tv_location_end_snatch;
    @Bind(R.id.tv_distance_snatch)
    TextView tv_distance_snatch;
    @Bind(R.id.tv_runmoney_snatch)
    TextView tv_runmoney_snatch;
    @Bind(R.id.tv_goodmoney_snatch)
    TextView tv_goodmoney_snatch;
    @Bind(R.id.tv_note_snatch)
    TextView tv_note_snatch;
    @Bind(R.id.tv_bangTime)
    TextView tv_bangTime;
    @Bind(R.id.daojishi)
    TextView daojishi;
    @Bind(R.id.tv_start_snatch)
    TextView tv_start_snatch;
    @Bind(R.id.iv_type)
    ImageView iv_type;
    @Bind(R.id.lay_bangTime)
    LinearLayout lay_bangTime;
    @Bind(R.id.tv_start)
    ImageView tv_start;
    @Bind(R.id.tv_end)
    ImageView tv_end;
    @Bind(R.id.iv_start)
    ImageView iv_start;
    @Bind(R.id.iv_end)
    ImageView iv_end;
    @Bind(R.id.lay_goodmoney_snatch)
    LinearLayout lay_goodmoney_snatch;


    @Bind(R.id.tv_goods_type)
    TextView tv_goods_type;//物品类型
    @Bind(R.id.ll_goods)
    LinearLayout ll_goods;
    @Bind(R.id.ll_distance)
    LinearLayout ll_distance;
    @Bind(R.id.ll_hotbox)
    LinearLayout ll_hotbox;
    @Bind(R.id.tv_hotbox)
    TextView tv_hotbox;
    @Bind(R.id.ll_feemoney)
    LinearLayout ll_feemoney;
    @Bind(R.id.tv_feemoney)
    TextView tv_feemoney;
    @Bind(R.id.ll_addmoney)
    LinearLayout ll_addmoney;
    @Bind(R.id.tv_addmoney)
    TextView tv_addmoney;
    @Bind(R.id.tv_juli)
    TextView tv_juli;
    @Bind(R.id.tv_distance_danwei)
    TextView tv_distance_danwei;


    @Bind(R.id.ll_paidui)
    LinearLayout ll_paidui;
    @Bind(R.id.tv_paidui_time)
    TextView tv_paidui_time;
    @Bind(R.id.lay_beizhu)
    LinearLayout lay_beizhu;

    /**
     * 地图实例
     */
    private BaiduMap mBaiduMap;
    //    百度地图路径规划
    int nodeIndex = -1; // 节点索引,供浏览节点时使用
    RouteLine route = null;
    OverlayManager routeOverlay = null;
    boolean useDefaultIcon = false;
    // 搜索相关
    RoutePlanSearch mSearch = null;
    LatLng lat_start, lat_end;
    private OrderModel orderModel;

    private String type;

    private DaoJiShi daoJiShi;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        orderModel = Tools.JsonToJavabean(getIntent().getStringExtra("OrderDetail"), OrderModel.class);
        type=getIntent().getStringExtra("type");
        setContentView(R.layout.activity_push_order);
        ButterKnife.bind(this);
        mapviewSnatch.removeViewAt(1);
        initBaiduMap();
        initview();
        daoJiShi=new DaoJiShi(PushOrderActivity.this, 4000, 1000, daojishi,tv_start_snatch);
        daoJiShi.start();
    }
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        orderModel = Tools.JsonToJavabean(intent.getStringExtra("OrderDetail"), OrderModel.class);
        type=intent.getStringExtra("type");
        initview();
    }
    private void initview() {
        switch (orderModel.getOrderType()) {
            case "0"://实时
                if(type.equals("0")){//推送
                    iv_type.setImageDrawable(getResources().getDrawable(R.mipmap.sy_shishi));
                    lay_bangTime.setVisibility(View.GONE);
                }else {//指派
                    iv_type.setImageDrawable(getResources().getDrawable(R.mipmap.sy_zhipai));
                    lay_bangTime.setVisibility(View.GONE);
                }
                break;
            case "1"://预约
                if(type.equals("0")){//推送
                    iv_type.setImageDrawable(getResources().getDrawable(R.mipmap.sy_yuyue));
                    lay_bangTime.setVisibility(View.VISIBLE);
                }else {//指派
                    iv_type.setImageDrawable(getResources().getDrawable(R.mipmap.sy_zhipai));
                    lay_bangTime.setVisibility(View.VISIBLE);
                }
                break;
            case "2"://指派
                iv_type.setImageDrawable(getResources().getDrawable(R.mipmap.sy_zhipai));
                lay_bangTime.setVisibility(View.GONE);
                break;
        }
        tv_bangTime.setText(orderModel.getSubscribeTime());
        tv_goods_type.setText(orderModel.getQuickOpers());
        tv_runmoney_snatch.setText(orderModel.getDriverFreightMoney());
        if (orderModel.getHotBox().equals("1")) {
            ll_hotbox.setVisibility(View.VISIBLE);//
            tv_hotbox.setText("保温箱");
        } else {
            ll_hotbox.setVisibility(View.GONE);//
        }
        if (orderModel.getPayUserFeeMoney().equals("0.00元")) {
            ll_feemoney.setVisibility(View.GONE);
        } else {
            ll_feemoney.setVisibility(View.VISIBLE);
            tv_feemoney.setText(orderModel.getPayUserFeeMoney());
        }
        if(orderModel.getSysAddMoney().equals("0.00元")){
            ll_addmoney.setVisibility(View.GONE);
        }else {
            ll_addmoney.setVisibility(View.VISIBLE);
            tv_addmoney.setText(orderModel.getSysAddMoney());
        }
        if(orderModel.getRemarks().equals("")){
            lay_beizhu.setVisibility(View.GONE);
        }else {
            tv_note_snatch.setText(orderModel.getRemarks());
        }
        if (Double.valueOf(orderModel.getDTakeDist()) < 1000) {
            String str=Math.ceil(Double.valueOf(orderModel.getDTakeDist()))+"";
            tv_distancd.setText(Html.fromHtml(str));
            tv_juli.setText("米");
        } else {
            String str=new java.text.DecimalFormat("#.00").format(Double.valueOf(orderModel.getDTakeDist()) / 1000);
            tv_distancd.setText(Html.fromHtml(str));
            tv_juli.setText("公里");
        }
        iv_start.setBackgroundDrawable(getResources().getDrawable(R.mipmap.paiduididian));
        iv_end.setBackgroundDrawable(getResources().getDrawable(R.mipmap.sy_paiduixinxi));
        tv_start.setBackgroundDrawable(getResources().getDrawable(R.mipmap.zuobiao_01));
        tv_end.setBackgroundDrawable(getResources().getDrawable(R.mipmap.zuobiao_02));
        switch (orderModel.getSendType()) {
            case "10"://送
                tv_ordertype_snatch.setText("同城送");
                tv_location_start_snatch.setText(orderModel.getBegAddress());
                tv_location_end_snatch.setText(orderModel.getEndAddress());
                if (Double.valueOf(orderModel.getPushDistance()) < 1000) {
                    tv_distance_snatch.setText(Math.ceil(Double.valueOf(orderModel.getPushDistance()))+"");
                    tv_distance_danwei.setText("米");
                } else {
                    tv_distance_snatch.setText(new java.text.DecimalFormat("#.00").format(Double.valueOf(orderModel.getPushDistance()) / 1000)+"");
                    tv_distance_danwei.setText("公里");
                }
                iv_start.setVisibility(View.GONE);
                iv_end.setVisibility(View.GONE);
                tv_start.setVisibility(View.VISIBLE);
                tv_end.setVisibility(View.VISIBLE);
                ll_paidui.setVisibility(View.GONE);//
                ll_distance.setVisibility(View.VISIBLE);//
                ll_goods.setVisibility(View.GONE);//
                break;
            case "20"://取
                tv_ordertype_snatch.setText("同城取");
                tv_location_start_snatch.setText(orderModel.getBegAddress());
                tv_location_end_snatch.setText(orderModel.getEndAddress());
                if (Double.valueOf(orderModel.getPushDistance()) < 1000) {
                    tv_distance_snatch.setText(Math.ceil(Double.valueOf(orderModel.getPushDistance()))+"");
                    tv_distance_danwei.setText("米");
                } else {
                    tv_distance_snatch.setText(new java.text.DecimalFormat("#.00").format(Double.valueOf(orderModel.getPushDistance()) / 1000)+"");
                    tv_distance_danwei.setText("公里");
                }
                iv_start.setVisibility(View.GONE);
                iv_end.setVisibility(View.GONE);
                tv_start.setVisibility(View.VISIBLE);
                tv_end.setVisibility(View.VISIBLE);
                ll_paidui.setVisibility(View.GONE);//
                ll_distance.setVisibility(View.VISIBLE);//
                ll_goods.setVisibility(View.GONE);//

                break;
            case "30"://买
                tv_ordertype_snatch.setText("同城买");
                if(orderModel.getSendSubType().equals("301")){
                    tv_location_start_snatch.setText("就近买(不限制购买地址)");
                }else {
                    tv_location_start_snatch.setText(orderModel.getBegAddress());
                }

                tv_location_end_snatch.setText(orderModel.getEndAddress());
                if (Double.valueOf(orderModel.getPushDistance()) < 1000) {
                    tv_distance_snatch.setText(Math.ceil(Double.valueOf(orderModel.getPushDistance()))+"");
                    tv_distance_danwei.setText("米");
                } else {
                    tv_distance_snatch.setText(new java.text.DecimalFormat("#.00").format(Double.valueOf(orderModel.getPushDistance()) / 1000)+"");
                    tv_distance_danwei.setText("公里");
                }
                if(orderModel.getPayGoodsMoney().equals("0.00")){
                    tv_goodmoney_snatch.setText("以小票为准");
                }else {
                    tv_goodmoney_snatch.setText(orderModel.getPayGoodsMoney() + "元");
                }
                iv_start.setVisibility(View.GONE);
                iv_end.setVisibility(View.GONE);
                tv_start.setVisibility(View.VISIBLE);
                tv_end.setVisibility(View.VISIBLE);
                ll_paidui.setVisibility(View.GONE);//
                ll_distance.setVisibility(View.VISIBLE);//
                ll_goods.setVisibility(View.VISIBLE);//
                break;
            case "40"://帮
                tv_ordertype_snatch.setText("同城帮");
                tv_location_start_snatch.setText(orderModel.getBegAddress());
                if(orderModel.getHelpInfo().equals("")){
                    tv_location_end_snatch.setText("暂无");
                }else {
                    tv_location_end_snatch.setText(orderModel.getHelpInfo());
                }
                iv_start.setVisibility(View.VISIBLE);
                iv_end.setVisibility(View.VISIBLE);
                tv_start.setVisibility(View.GONE);
                tv_end.setVisibility(View.GONE);
                ll_paidui.setVisibility(View.GONE);//
                ll_distance.setVisibility(View.GONE);//
                tv_distance_danwei.setVisibility(View.GONE);
                ll_goods.setVisibility(View.GONE);//
                break;
            case "50"://排
                tv_ordertype_snatch.setText("同城排");
                tv_location_start_snatch.setText(orderModel.getBegAddress());
                if(orderModel.getHelpInfo().equals("")){
                    tv_location_end_snatch.setText("暂无");
                }else {
                    tv_location_end_snatch.setText(orderModel.getHelpInfo());
                }
                iv_start.setVisibility(View.VISIBLE);
                iv_end.setVisibility(View.VISIBLE);
                tv_start.setVisibility(View.GONE);
                tv_end.setVisibility(View.GONE);
                ll_paidui.setVisibility(View.VISIBLE);//
                ll_distance.setVisibility(View.GONE);//
                tv_distance_danwei.setVisibility(View.GONE);
                ll_goods.setVisibility(View.GONE);//
                tv_paidui_time.setText(orderModel.getExTimeSpan() + "分钟");//


                tv_start.setBackgroundResource(R.mipmap.paiduididian);
                tv_end.setBackgroundResource(R.mipmap.sy_paiduixinxi);
                break;
        }
    }

    @OnClick({R.id.image_finish_snatch, R.id.tv_detail_snatch, R.id.tv_map_snatch, R.id.tv_start_snatch})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.image_finish_snatch://关闭当前页面
                EventBus.getDefault().post(new EventCenter<String>(-9,"关闭播报"));
                finish();
                break;
            case R.id.tv_detail_snatch://订单详情
                lay_detail_snatch.setVisibility(View.VISIBLE);
                lay_map_snatch.setVisibility(View.GONE);
                tv_detail_snatch.setTextColor(getResources().getColor(R.color.mainRed));
                tv_map_snatch.setTextColor(getResources().getColor(R.color.mainText));
                break;
            case R.id.tv_map_snatch://订单地图
                showlines();
                lay_detail_snatch.setVisibility(View.GONE);
                lay_map_snatch.setVisibility(View.VISIBLE);
                tv_detail_snatch.setTextColor(getResources().getColor(R.color.mainText));
                tv_map_snatch.setTextColor(getResources().getColor(R.color.mainRed));
                break;
            case R.id.tv_start_snatch://抢单
//                if(orderModel != null && orderModel.getOrderType().equals("2")){
//                    EventBus.getDefault().post(new EventCenter<String>(-11, "抢单"));
//                    finish();
//                }else {
                    grab(orderModel.getID());
                //}
                break;
        }
    }

    private void grab(String orderId) {
        Call<CommonResponse> httpResultCall = RetrofitUtils.getRequest(PushOrderActivity.this, true).grab(orderId, PreferencesUtils.getString(MyApp.getContext(), "userID"), 0, Tools.javabeanToJson(ChcheUtils.getInstance().getLocationModel()));
        httpResultCall.enqueue(new HttpCallBack<CommonResponse>() {
            @Override
            public void onSuccess(Object t) {
                CommonResponse commonResponse = (CommonResponse) t;
                ToastUtil.getInstance().show(commonResponse.getMessage());
                EventBus.getDefault().post(new EventCenter<String>(111, "抢单成功"));
                EventBus.getDefault().post(new EventCenter<String>(-9,"关闭播报"));
                finish();
            }

            @Override
            public void onFail(int code, String message) {
                if (code == 40104) {
                    grab(orderId);
                } else {
                    ToastUtil.getInstance().show(message);
                    EventBus.getDefault().post(new EventCenter<String>(-9,"关闭播报"));
                    finish();
                }
            }
        });
    }
    private void initBaiduMap() {
        mBaiduMap = mapviewSnatch.getMap();

        if (ChcheUtils.getInstance().getLocationModel() == null)
            return;
        initOver(ChcheUtils.getInstance().getLocationModel().getLat(),
                ChcheUtils.getInstance().getLocationModel().getLng());
        if (orderModel.getSendType().equals("10") || orderModel.getSendType().equals("20") || orderModel.getSendType().equals("30")) {
            lat_start = new LatLng(Double.parseDouble(orderModel.getBegLocLat()), Double.parseDouble(orderModel.getBegLocLng()));
            lat_end = new LatLng(Double.parseDouble(orderModel.getEndLocLat()), Double.parseDouble(orderModel.getBegLocLng()));

        } else if (orderModel.getSendType().equals("40") || orderModel.getSendType().equals("50")) {
            lat_start = new LatLng(ChcheUtils.getInstance().getLocationModel().getLat(), ChcheUtils.getInstance().getLocationModel().getLng());
            lat_end = new LatLng(Double.parseDouble(orderModel.getBegLocLat()), Double.parseDouble(orderModel.getBegLocLng()));
        }
        mSearch = RoutePlanSearch.newInstance();
        mSearch.setOnGetRoutePlanResultListener(this);
    }

    private void initOver(double a, double b) {
        //定义Maker坐标点
        LatLng point = new LatLng(a, b);
        //构建Marker图标
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.mipmap.dangqianweizhi);
        //构建MarkerOption，用于在地图上添加Marker
        OverlayOptions option = new MarkerOptions()
                .position(point)
                .icon(bitmap);
        //在地图上添加Marker，并显示
        mBaiduMap.addOverlay(option);
    }

    private void initErrorOver(double a, double b) {
        //定义Maker坐标点
        LatLng point = new LatLng(a, b);
        //构建Marker图标
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.mipmap.dingweizhi);
        //构建MarkerOption，用于在地图上添加Marker
        OverlayOptions option = new MarkerOptions()
                .position(point)
                .icon(bitmap);
        //在地图上添加Marker，并显示
        mBaiduMap.addOverlay(option);
    }

    /**
     * 显示路线
     */
    private void showlines() {
        // 重置浏览节点的路线数据
        route = null;
        //mBaiduMap.clear();
        PlanNode stNode = PlanNode.withLocation(lat_start);
        PlanNode enNode = PlanNode.withLocation(lat_end);
        mSearch.bikingSearch((new BikingRoutePlanOption())
                .from(stNode).to(enNode));
    }

    @Override
    public void onMapClick(LatLng latLng) {

    }

    @Override
    public boolean onMapPoiClick(MapPoi mapPoi) {
        return false;
    }

    @Override
    public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {

    }

    @Override
    public void onGetTransitRouteResult(TransitRouteResult transitRouteResult) {

    }

    @Override
    public void onGetMassTransitRouteResult(MassTransitRouteResult result) {
    }

    @Override
    public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {

    }

    @Override
    public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {

    }

    @Override
    public void onGetBikingRouteResult(BikingRouteResult bikingRouteResult) {
        if (bikingRouteResult.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
            LatLng ll = new LatLng(ChcheUtils.getInstance().getLocationModel().getLat(),
                    ChcheUtils.getInstance().getLocationModel().getLng());
            MapStatus.Builder builder = new MapStatus.Builder();
            builder.target(ll).zoom(17.0f);
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
            initErrorOver(Double.parseDouble(orderModel.getBegLocLat()), Double.parseDouble(orderModel.getBegLocLng()));
            return;
        }
        if (bikingRouteResult == null || bikingRouteResult.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(PushOrderActivity.this, "抱歉，未找到结果", Toast.LENGTH_SHORT).show();
        }
        if (bikingRouteResult.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
            // 起终点或途经点地址有岐义，通过以下接口获取建议查询信息
            // result.getSuggestAddrInfo()
            return;
        }
        if (bikingRouteResult.error == SearchResult.ERRORNO.NO_ERROR) {
            nodeIndex = -1;
            route = bikingRouteResult.getRouteLines().get(0);
            BikingRouteOverlay overlay = new MyBikingRouteOverlay(mBaiduMap);
            routeOverlay = overlay;
            mBaiduMap.setOnMarkerClickListener(overlay);
            overlay.setData(bikingRouteResult.getRouteLines().get(0));//设置路线数据
            overlay.addToMap();//将所有overlay添加到地图中
            overlay.zoomToSpan(); //缩放地图
        }
        MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
        mBaiduMap.setMapStatus(msu);
    }

    private class MyBikingRouteOverlay extends BikingRouteOverlay {

        public MyBikingRouteOverlay(BaiduMap baiduMap) {
            super(baiduMap);
        }

        @Override
        public BitmapDescriptor getStartMarker() {
            if (useDefaultIcon) {
                return BitmapDescriptorFactory.fromResource(R.mipmap.icon_st);
            }
            return null;
        }
        @Override
        public BitmapDescriptor getTerminalMarker() {
            if (useDefaultIcon) {
                return BitmapDescriptorFactory.fromResource(R.mipmap.icon_en);
            }
            return null;
        }
    }

    public class DaoJiShi extends CountDownTimer {
        private final Context baseContent;
        TextView button;
        TextView tv_qiang;

        public DaoJiShi(Context content, long millisInFuture, long countDownInterval, TextView bt,TextView tv) {
            super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
            baseContent = content;
            this.button = bt;
            this.tv_qiang=tv;
        }

        @Override
        public void onFinish() {// 计时完毕时触发
//          button.setText("获取验证码");
            button.setText("");
            button.setClickable(true);
            button.setVisibility(View.GONE);
           // if (type != null && type.equals("2")) {
              //  tv_start_snatch.setText("查看\n详情");
            //} else {
            tv_qiang.setText("抢单");
            //}
//            if (orderModel != null && orderModel.getOrderType().equals("2")) {
//                tv_start_snatch.setText("查看\n详情");
//            } else {
//                tv_start_snatch.setText("抢单");
//            }
            tv_qiang.setVisibility(View.VISIBLE);

        }

        @Override
        public void onTick(long millisUntilFinished) {// 计时过程显示
            button.setClickable(false);
            button.setTextColor(baseContent.getResources().getColor(R.color.white));
            button.setText(millisUntilFinished / 1000 + "");
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        mapviewSnatch.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapviewSnatch.onPause();
    }

    @Override
    public void onBackPressed() {
        EventBus.getDefault().post(new EventCenter<String>(-9,"关闭播报"));
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
        daoJiShi.cancel();
    }
}
